<?php
$marginPages = 2;
$pages = [];
if ($paginator->lastPage() > 10) {
    if ($paginator->currentPage() <= $marginPages + 1) {
        $pages = [1, 2, 3, 4, 5];
    } else if ($paginator->currentPage() >= $paginator->lastPage() - ($marginPages + 1)) {
        $pages = [
            $paginator->lastPage() - 4,
            $paginator->lastPage() - 3,
            $paginator->lastPage() - 2,
            $paginator->lastPage() - 1,
            $paginator->lastPage()
        ];
    } else {
//        $pages[] = -1;
        for ($i = $paginator->currentPage() - $marginPages; $i <= $paginator->currentPage() + $marginPages; $i++) {
            $pages[] = $i;
        }
//        $pages[] = -1;

    }
} else {
    for ($i = 1; $i <= $paginator->lastPage(); $i++) {
        $pages[] = $i;
    }
}


?>


<div class="navigator"
<?php if ($paginator->lastPage() <= 1) {
    echo 'style="display:none"';
}?>>

    @if ($paginator->lastPage() > 1)

        <ul class="pagination d-flex justify-content-end">

            @foreach ($pages as $i)

                <li class="pages-item {{ ($paginator->currentPage() == $i) ? ' active' : ''}}">
                    <a href="{{ $paginator->url($i) }}"  class="page-link m-1"> {{ $i }}</a>
                </li>
            @endforeach
                <li class="pages-item ml-3">
                <a href="{{ $paginator->url($paginator->currentPage()-1) }}"
                   class="up m-1 page-link {{ ($paginator->currentPage() == 1) ? ' disabled' : '' }}">
                    <
                </a>
                </li>
                @if($paginator->currentPage()<$paginator->lastPage())
                    <li class="pages-item">
                    <a href="{{ $paginator->url($paginator->currentPage()+1) }}"
                       class="down m-1 page-link {{ ($paginator->currentPage() == $paginator->lastPage()) ? ' disabled' : '' }}">
                        >
                    </a>
                    </li>
                @else
                    <li class="pages-item">
                    <a href="#"
                       class="down m-1 page-link {{ ($paginator->currentPage() == $paginator->lastPage()) ? ' disabled' : '' }}">
                        >
                    </a>
                    </li>
                @endif
        </ul>
    @endif
</div>


